package licode.unisop.oidc.auth.modal;

import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * @author licode
 */
@Data
public class SsoToken implements Serializable {
    private static final long serialVersionUID = 6058046621327759771L;

    /**
     * 单点登录超时时间（单位：秒）
     */
    private long timeout;

    /**
     * 单点登录的会话令牌
     */
    private String ssoToken;

    /**
     * 创建时间
     */
    private Long createTime;

    public SsoToken(String token, long t) {
        setSsoToken(token, t);
        createTime = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
    }

    public void setSsoToken(String ssoToken, long t) {
        this.ssoToken = ssoToken;
        timeout = t + System.currentTimeMillis() / 1000;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }
}
